package com.mdd.front.controller;

import com.mdd.common.aop.NotLogin;
import com.mdd.common.util.UrlUtils;
import com.mdd.front.service.IProductService;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("api/product")
public class ProductController {

    @Resource
    IProductService iProductService;

    @NotLogin
    @GetMapping("/list")
    public AjaxResult list(@RequestParam Map<String, String> params) {
        return AjaxResult.success(iProductService.list(params));
    }

    @NotLogin
    @GetMapping("/detail/{id}")
    public AjaxResult detail(@Validated @IDMust @PathVariable("id") Integer id) {
        Map<String, Object> detail = iProductService.detail(id);
        if (detail == null) {
            return AjaxResult.failed("产品不存在");
        }
        return AjaxResult.success(detail);
    }
    @NotLogin
    @GetMapping("/category")
    public AjaxResult category() {
        return AjaxResult.success(iProductService.category());
    }
}